<template>
    <div class="container">
        <div class="login-modal">
            <div class="login-modal__title">
                {{ modalTitle }}
            </div>

            <div class="login-form" :style="type === 3 ? 'margin-top: 29px' : ''">
                <el-input type="text" size="large" v-model="phone" placeholder="请输入你的手机号" @keyup.enter="onSubmit">
                    <template #prepend>
                        <el-select v-model="num" size="large" style="width: 80px">
                            <el-option label="+86" :value="86" />
                        </el-select>
                    </template>
                </el-input>

                <el-input type="text" size="large" v-model="code" placeholder="请输入验证码"
                    :style="`margin-top: ${type === 3 ? 10 : 20}px`" v-if="type === 2 || type === 3"
                    @keyup.enter="onSubmit">
                    <template #append>
                        <el-button @click="onSendCode">{{
                            codeText
                        }}</el-button>
                    </template>
                </el-input>

                <el-input type="password" size="large" v-model="password" placeholder="请输入密码"
                    :style="`margin-top: ${type === 3 ? 10 : 20}px`" v-if="type === 1 || type === 3" @keyup.enter="onSubmit"
                    show-password>
                </el-input>

                <el-date-picker v-if="type === 3" v-model="birthday" type="date" size="large" class="no-icon"
                    :prefix-icon="false" :clearable="false" placeholder="请选择出生日期"
                    :style="`margin-top: ${type === 3 ? 10 : 20}px`" :disabledDate="birthdayDisabled"
                    value-format="YYYY-MM-DD"></el-date-picker>

                <!-- <el-input
                    type="text"
                    size="large"
                    v-model="experience_code"
                    placeholder="请输入体验码（选填，获取请留言）"
                    style="margin-top: 10px"
                    v-if="type === 3"
                    @keyup.enter="onSubmit"
                >
                </el-input> -->

                <div class="form-footer" v-if="type === 1">
                    <div class="remember-password">
                        <el-checkbox v-model="rememberPassword" size="small">记住密码</el-checkbox>
                    </div>
                    <span class="forgot-pwd" @click="onForgetPwd">
                        忘记密码？
                    </span>
                </div>
            </div>

            <div class="login-btn" @click="onSubmit" :style="{ marginTop: type === 3 ? '15px' : '60px' }">
                {{ type === 3 ? "注册" : "登录" }}
            </div>

            <div class="login-footer" :style="{ marginTop: type === 3 ? '10px' : '30px' }">
                <template v-if="type !== 3">
                    <div class="btn-group" @click="toRegister">
                        <img :src="`${_oss_}images/login/register.png`" />
                        立即注册
                    </div>
                    <div class="btn-group" @click="onChangeType(1)" v-if="type !== 1">
                        <img :src="`${_oss_}images/login/password.png`" />
                        密码登录&emsp;
                    </div>
                    <div class="btn-group" @click="onChangeType(2)" v-if="type !== 2">
                        <img :src="`${_oss_}images/login/password.png`" />
                        验证码登录
                    </div>
                </template>

                <template v-else>
                    <div class="login-btn-group">
                        <span @click="onChangeType(1)">密码登录</span>
                    </div>
                </template>
            </div>
        </div>
    </div>
</template>
<script setup>
import { useContent } from ".";

const {
    type,
    num,
    phone,
    birthday,
    password,
    codeText,
    experience_code,
    code,
    rememberPassword,
    modalTitle,
    birthdayDisabled,
    onSendCode,
    onChangeType,
    onForgetPwd,
    onSubmit,
    toRegister
} = useContent();
</script>
<style lang="scss" scoped>
.container {
    position: relative;
    width: 100%;
    height: calc(100vh - 70px);
    background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/login/bg.jpg");
    background-size: cover;
}

.login-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 350px;
    height: 400px;
    padding: 0 24px 0 26px;
    background: #ffffff;
    border-radius: 10px;
    transform: translate(-50%, -50%);
    box-sizing: border-box;

    &__title {
        text-align: center;
        margin-top: 39px;
        font-size: 30px;
    }

    .login-form {
        position: relative;
        margin-top: 39px;

        .form-footer {
            width: 100%;
            position: absolute;
            left: 0;
            bottom: -30px;
            display: flex;
            align-items: center;
            justify-content: space-between;

            .forgot-pwd {
                color: #5185fb;
                font-size: 12px;
                cursor: pointer;
                user-select: none;
            }
        }
    }

    .login-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 40px;
        font-size: 18px;
        color: #fff;
        background-color: #5185fb;
        border-radius: 6px;
        cursor: pointer;
        user-select: none;
    }

    .login-footer {
        display: flex;
        justify-content: center;
        margin-top: 30px;
        color: #666;
        font-size: 14px;

        .btn-group {
            display: flex;
            align-items: center;
            cursor: pointer;
            user-select: none;

            &:first-of-type {
                margin-right: 40px;
            }

            img {
                margin-right: 6px;
                color: #666;
                font-size: 14px;
            }
        }
    }
}

.login-btn-group {
    text-align: center;
    color: #5185fb;
    cursor: pointer;
    user-select: none;
}

:deep(.no-icon) {
    width: 100%;

    .el-input__prefix {
        display: none !important;
    }
}
</style>
